package com.inspectortime.domain.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.inspectortime.common.PersistentEntityBase;
import com.inspectortime.domain.Inspection;
import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.domain.OptionalService;
import com.inspectortime.timestamp.Timestamped;

@Entity
@Table(name = "OPTIONAL_SERVICE")
public class OptionalServiceImpl extends PersistentEntityBase implements Timestamped, OptionalService {
	
	private InspectorCompany company;
	private Date createdTime;
	private String description;
	private Date lastModifiedTime;
	private double price;
	private String title;
	
	/** 
	 * @see http://www.coderanch.com/t/216578/Object-Relational-Mapping/java/Hibernate-cascade-deletion-many-many
	 */
	private List<Inspection> inspections = new ArrayList<Inspection>();
	
	@ManyToOne(targetEntity = InspectorCompanyImpl.class, cascade = { CascadeType.ALL })
	public InspectorCompany getCompany() {
		return company;
	}
	
	@ManyToMany(targetEntity = InspectionImpl.class, mappedBy="optionalServices", cascade = {CascadeType.ALL})
	public List<Inspection> getInspections() {
		return inspections;
	}
	
	public void setInspections(List<Inspection> inspections) {
		this.inspections = inspections;
	}

	public Date getCreatedTime() {
		return createdTime;
	}
	
	@Column( length = 255 )
	public String getDescription() {
		return description;
	}
	public Date getLastModifiedTime() {
		return lastModifiedTime;
	}
	
	public double getPrice() {
		return price;
	}
	@Column( length = 100 )
	public String getTitle() {
		return title;
	}
	
	public void setCompany(InspectorCompany company) {
		this.company = company;
	}
	public void setCreatedTime(Date created) {
		this.createdTime = created;		
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public void setLastModifiedTime(Date modified) {
		this.lastModifiedTime = modified;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	}
